import formDownload from 'src/hrpub/common/utils/download/download';
import {
    toast,
    //formDownload
} from 'nc-lightapp-front';
import {unZipAndDecryptForForm} from 'src/hrpub/common/utils/unZipAndDecrypt';

export default function exportPsnPhoto(param_str) {
    let postData = {
        pk_org: this.props.orgVal.refpk,
        param_str
    };
    /*return formDownload({
        params: postData,
        url: '/nccloud/hrhi/psndoc/PsndocExportPhotoAction.do',
        enctype: 2
    })*/

    return formDownload({
        body: postData,
        url: '/nccloud/hrhi/psndoc/PsndocExportPhotoAction.do',
        enctype: 2,
        onResult: (resBody) => {
            let innerText = resBody.innerText;
            let res = {};
            try {
                res = JSON.parse(innerText);
                if (typeof res === 'string') {
                    throw new Error();
                }
            } catch (e) {
                res = unZipAndDecryptForForm(resBody.innerText);
            }
            if (!res.success) {
                toast({
                    color: 'danger',
                    content: res.error.message
                });
            }
        }
    });
}
